//
//  TrainDetailController.swift
//  健身宝
//
//  Created by hzt on 2017/10/12.
//  Copyright © 2017年 hzt. All rights reserved.
//

import UIKit

class TrainDetailController: UIViewController {
    var infoDict:NSDictionary!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        viewConfig()
        //viewWillAppear()
    }
    
    func viewConfig(){
        view.backgroundColor = UIColor.white
        
        //        let navBar = CustomNavBar(frame: CGRect(origin: .zero, size: CGSize(width: WIDTH, height: 64)))
        //        navBar.initialize(text: nil)
        //        view.addSubview(navBar)
        self.navigationController?.isNavigationBarHidden = true
        self.rdv_tabBarController?.isTabBarHidden = true
        let scrollView = UIScrollView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height-64))
        //scrollView.contentInsetAdjustmentBehavior = .never
        scrollView.contentSize = CGSize(width: 0, height: 364+(UIScreen.main.bounds.height-69)/3)
        scrollView.backgroundColor = view.backgroundColor
        scrollView.showsVerticalScrollIndicator = false
        view.addSubview(scrollView)
        
        let imageView = UIImageView()
        let pURL = "http://172.24.10.175/workout/Uploads/"
        imageView.sd_setImage(with: URL(string: pURL+(infoDict.value(forKey: "thumb") as! String)), placeholderImage: UIImage(named:"placeholder"))
        imageView.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: (UIScreen.main.bounds.height-69)/3)
        scrollView.addSubview(imageView)
        
        let label = UILabel(frame: CGRect(x: 15, y: imageView.bounds.height+10, width: UIScreen.main.bounds.width-30, height: 40))
        label.text = "简介"
        label.textAlignment = .center
        label.layer.cornerRadius = 5
        label.layer.borderColor = UIColor.lightGray.cgColor
        label.layer.borderWidth = 1
        scrollView.addSubview(label)
        
        let textView = UITextView(frame: CGRect(x: 15, y: label.frame.origin.y+50, width: UIScreen.main.bounds.width-30, height: 140))
        textView.text = infoDict.value(forKey: "introduction") as! String
        textView.isEditable = false
        textView.font = UIFont.systemFont(ofSize: 16)
        textView.layer.borderWidth = 1
        textView.layer.borderColor = UIColor.lightGray.cgColor
        scrollView.addSubview(textView)
        
        let timeLabel = UILabel(frame: CGRect(x: 15, y: textView.frame.origin.y+160, width: UIScreen.main.bounds.width-30, height: 20))
        timeLabel.text = "发布时间: \(infoDict.value(forKey: "update_time") as! String)"
        timeLabel.font = UIFont.systemFont(ofSize: 20)
        scrollView.addSubview(timeLabel)
        
        let addLabel = UILabel(frame: CGRect(x: 15, y: timeLabel.frame.origin.y+40, width: UIScreen.main.bounds.width-30, height: 20))
        addLabel.text = "地点: \(infoDict.value(forKey: "scene_name") as! String)"
        addLabel.font = UIFont.systemFont(ofSize: 20)
        scrollView.addSubview(addLabel)
        
        let backBtn = UIButton(frame: CGRect(x: 16, y: 0, width: 35, height: 30))
        backBtn.titleLabel?.font = UIFont.systemFont(ofSize: 17)
        backBtn.setTitle("返回", for: .normal)
        backBtn.setTitleColor(.black, for: .normal)
        scrollView.addSubview(backBtn)
        backBtn.addTarget(self, action: #selector(back), for: .touchUpInside)

        //self.rdv_tabBarController.isTabBarHidden = true
//        let addrLabel = UILabel(frame: CGRect(x: 15, y: telLabel.frame.origin.y+40, width: UIScreen.main.bounds.width-30, height: 20))
//        let addr = (infoDict.value(forKey: "province_name") as! String)+(infoDict.value(forKey: "city_name") as! String)+(infoDict.value(forKey: "district_name") as! String)
//        addrLabel.text = "具体地址: \(addr)"
//        addrLabel.font = UIFont.systemFont(ofSize: 20)
//        scrollView.addSubview(addrLabel)
        
        //        let joinBtn = UIButton(frame: CGRect(x: 0, y: addrLabel.frame.origin.y+60, width: 150, height: 44))
        //        joinBtn.backgroundColor = UIColor.red
        //        joinBtn.center.x = UIScreen.main.bounds.width/2
        //        joinBtn.setTitle("加入俱乐部", for: .normal)
        //        joinBtn.layer.cornerRadius = 8
        //        joinBtn.adjustsImageWhenDisabled = false
        //        scrollView.addSubview(joinBtn)
        
        //        joinBtn.addTarget(self, action: #selector(joinClub), for: .touchUpInside)
        //
        //        navBar.backBtn.addTarget(self, action: #selector(back), for: .touchUpInside)
    }
    
    //    @objc func joinClub(sender:UIButton){
    //        sender.isEnabled = false
    //        let parameter:NSDictionary = [
    //            "mod"       :   "clubmember",
    //            "SessionID" :   LoginModel.sessionID,
    //            "club_id"   :   infoDict.value(forKey: "id") as! String,
    //            "userid"    :   LoginModel.userID
    //        ]
    //        Networking.shared.joinClub(parameter: parameter) {
    //            DispatchQueue.main.async {
    //                let popup = Popup()
    //                popup.appear(title: "加入成功", action: {
    //                    self.back()
    //                })
    //            }
    //        }
    //    }
    
    @objc func back(){
        _ = navigationController?.popViewController(animated: true)
        self.navigationController?.isNavigationBarHidden = false
        self.rdv_tabBarController?.isTabBarHidden = false
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
//    
//    func viewWillAppear() -> (ObjCBool){
//        super.viewWillAppear(true)
//        self.rdv_tabBarController.setTabBarHidden(true, animated:true)
//        return true
//    }
}



